package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo02 {
    public static void main(String[] args) {
        //获取连接
        try (Connection conn = DBUtils.getConn()){
            //查询SQL语句
            String sql = "select name,sal from emp";
            //SQL里面没有变量 所以使用Statement
            Statement s = conn.createStatement();
            //执行查询的SQL
            ResultSet rs = s.executeQuery(sql);
            //遍历结果
            while(rs.next()){
                //取出查询到的名字和工资
                String name= rs.getString(1);
                int sal = rs.getInt(2);
                System.out.println(name+":"+sal);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
